Skip to content

Conversation

balsemao
Copy link

@balsemao balsemao commented May 10, 2024

Adicionado o endpoint /supplies/top com os parâmetros page e perPage.

curl 'localhost:4000/supplies/top?perPage=3&page=1'
{
  "statusCode": 200,
  "message": "Successfully get top supplies",
  "data": [
    {
      "name": "1 Notebook pode ser usado",
      "amount": 1
    },
    {
      "name": "Aparelho de barbear",
      "amount": 1
    },
    {
      "name": "Turnos de manhã",
      "amount": 1
    }
  ]
}

Em seguida atualizo com o filtro por abrigo.

@Get('top')
async top(@Query('limit') limit: number = 10, @Query('skip') skip: number) {
try {
if (limit && typeof limit === 'string') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

é só usar o pipe ParseIntPipe

see: https://docs.nestjs.com/pipes#built-in-pipes

Copy link
Author

@balsemao balsemao May 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Boa, ajustado!

@balsemao
Copy link
Author

Vou precisar mudar a abordagem. O Prisma, ao que tudo indica, não suporta JOIN no aggregate(). Desta forma, vou precisar incluir a query bruta de SQL.

@balsemao
Copy link
Author

@AndersonCRocha atualizei o PR utilizando uma nova query para que sejam contados os top N items por abrigo. Incluído também o filtro por abrigo (shelterId, opcional)

@pastorini-cesar
Copy link

@balsemao Veja o que consegue usar desse commit cesarpastorini@e74abe5

@balsemao
Copy link
Author

@balsemao Veja o que consegue usar desse commit cesarpastorini@e74abe5

Valeu! Eu acabei fazendo o CAST para int na própria query e resolveu o problema.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants